from django.shortcuts import render
from django.http import HttpResponse
#from django.template import loader 

from rango.models import Category, Page

# Create your views here.
def index(request) :
  categery_list =  Category.objects.order_by('-likes')[:5]
  # context_dict = {'boldmessage': "Crunchy, creamy, cookie, candy, cupcake!"}
  context_dict = {'categories': categery_list}
  return render(request, 'rango/index.html', context = context_dict)

def about(request) :
  return HttpResponse("This is about page")

def show_category(request, category_name_slug):
  context_dict = []
  try:
    category = Category.objects.get(slug = category_name_slug)
    pages = Page.objects.filter(category = category)
    context_dict['pages'] = pages
    context_dict['category'] = category
  except Category.DoesNotExist:
    context_dict['pages'] = None 
    context_dict['category'] = None
  return render(request, 'rango/category.html', context = context_dict)